package com.dtagri.fjwlw.adapter;

import java.util.List;

import com.dtagri.fjwlw.R;
import com.dtagri.fjwlw.adapter.viewholders.ViewHolder;



import com.dtagri.fjwlw.bean.ServerBean;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

/**
 * 服务器适配器
 * @author CL.
 * 创建日期: 2015-11-19
 */
public class ServerAdapter extends BaseAdapter{
	private Context mContext;// 应用程序上下文
	private List listItems; // 信息集合
	private LayoutInflater mInflater;
	int index;

	public ServerAdapter(Context context, List list) {
		this.mContext = context;
		mInflater = LayoutInflater.from(context);
		this.listItems = list;
	}
	@Override
	public int getCount() {
		return listItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		return listItems.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.layout_server_list_item,parent, false);
			holder = new ViewHolder();
			holder.f0 = (TextView) convertView.findViewById(R.id.f0);
			holder.s0 = (TextView) convertView.findViewById(R.id.s0);
			holder.imgRadio = (ImageView) convertView.findViewById(R.id.list_radioImg);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		ServerBean info = (ServerBean) getItem(position);
		holder.f0.setText(info.getDescription());
		holder.s0.setText(info.getServerIp());
		Drawable drawable = mContext.getResources().getDrawable(Integer.parseInt(info.getImageStr()));
		holder.imgRadio.setBackgroundDrawable(drawable);
		return convertView;
	} 
	static class ViewHolder {
		TextView f0;
		TextView s0;
		ImageView imgRadio;
	}

}
